package com.zwr.sheller.shop.service.impl;

import com.zwr.sheller.core.pojo.Coupons;
import com.zwr.sheller.shop.mapper.CouponsMapper;
import com.zwr.sheller.shop.service.CouponsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 *
 *@author Kang
 *@date
 */
@Service("couponsService")
public class CouponsServiceImpl implements CouponsService {

    @Autowired(required = false)
    CouponsMapper couponsMapper;

    /**
     * 商户id
     */
    private  Long marketersId = 1L;

    @Override
    public Integer add(Coupons coupons) {
        coupons.setMarketersId(marketersId);
        int insert = couponsMapper.insert(coupons);
        return insert;
    }

    @Override
    public Integer delete(Long id) {
        Coupons coupons=new Coupons();
        coupons.setId(id);
        int delete = couponsMapper.delete(coupons);
        return delete;
    }

    @Override
    public Integer update(Coupons coupons) {
        int i = couponsMapper.updateByPrimaryKeySelective(coupons);

        return i;
    }

    @Override
    public List<Map<String, Object>> selectCouponsByNameByTimeByManner(Integer manner, Integer timePeriod, String name, Integer page, Integer varieties) {

        List<Map<String, Object>> mapList = couponsMapper.selectCouponsByNameByTimeByManner(manner, timePeriod, name, marketersId, (page - 1) * 3, varieties);

        return mapList;
    }

    @Override
    public Map selectCouponsByNameByTimeByMannerCount(Integer manner, Integer timePeriod, String name,  Integer varieties) {
        Map map = couponsMapper.selectCouponsByNameByTimeByMannerCount(manner, timePeriod, name, marketersId, varieties);
        return map;
    }


}
